package com.maxjay.component.simplelist.web.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.lang.StringUtils;

import com.maxjay.component.metadata.model.Record;
import com.maxjay.component.simplelist.model.QueryListField;

public class PageColumnTag extends BodyTagSupport {
	
	private String rowData;
	
	private String fieldName;
	
	private String field;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public int doStartTag() throws JspException {
		try {
			Object value = "";
			JspWriter out = pageContext.getOut();  
			Record record = (Record)pageContext.getAttribute(rowData);
			String fieldNameStr = fieldName;
			if(StringUtils.isBlank(fieldNameStr) && StringUtils.isNotBlank(field)){
				QueryListField listField = (QueryListField) pageContext.getAttribute(field);
				fieldNameStr = listField.getEntityField().getName();
			}
			value = record.getValue(fieldNameStr.toUpperCase());
			if(value == null){
				value = "";
			}
			out.write(value.toString());
        } catch (IOException e) {  
            throw new JspException(e);  
        }
        return EVAL_BODY_INCLUDE; //不包含主体内容  
	}

	public String getRowData() {
		return rowData;
	}

	public void setRowData(String rowData) {
		this.rowData = rowData;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}
	
}
